 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="crm.util.ParamUtil"%>
<%@page import="java.util.List"%>
<%@page import="crm.model.Customer"%>
<%@page import="crm.control.CustomerControl"%>
<%@page import="crm.util.GetBaseParam"%>
<%@page import="crm.control.SaleareaControl"%>
<%@page import="java.util.Collection"%>
<%@page import="java.util.Iterator"%>
<%@page import="crm.control.LinkmanControl"%>
<%@page import="crm.control.SaleareaControl"%>
<%@page import="crm.model.Linkman"%>
<%@page import="crm.model.Salearea"%>
<%@page import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../resources/css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../resources/css/copy.css" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src='../../../resources/js/jquery-1.6.2.min.js'></script>
<script type="text/javascript" src='../../../resources/js/WebCalendar.js''></script>
<script type="text/javascript">
$(function(){
		/*$(".trs").click(function{
		var value = $(this).children(".td").html();
		alert(value);*/
		//alert('');
		$(".trs").click(function(){
			var value = $(this).children(".td").html();
			var valueName = $(this).children(".td2").html();
			//alert(value2);
			window.opener.document.getElementById('consumerName').value=valueName;
			window.opener.document.getElementById('consumerId').value=value;
			 // window.opener.location.href = window.opener.location.href; 刷新父窗口
			  var browserName=navigator.appName;  
			                 if (browserName=="Netscape"){  
			                      // alert('chrome');   
			                       window.open('', '_parent', '');  
			                       window.close();  
			                 }  
			                 if (browserName=="Microsoft Internet Explorer") {   
			                     //  alert('ie');  
			                       window.parent.opener = "whocares";   
			                       window.parent.close();   
			                 }  
			               //如果你使用的是firefox浏览器必须要做以下设置 
			               //1、在地址栏输入about:config然后回车，警告确认 
			               //2、在过滤器中输入”dom.allow_scripts_to_close_windows“，双击即可将此//值设为true 

			})
			$('input:text').click(function(){
				return false;
				})
})
</script>

<script type="text/javascript">
$(document).ready(function(){
	var count = 0;
	$('#add_customer').hide();
	$('#show_add_linkman').hide();
		$('#show').click(function(){
			$('#add_customer').slideToggle();
			})
			$('#cancel').click(function() {
			$('#add_customer').fadeOut();
		})
		
		$('#add_linkman').click(function(){
			
			//  alert(count);
             $('#show_add_linkman').slideToggle();
             count++;
			})
			$('#submit_btn').click(function() {
				$.ajax( {
					type : "post",
					cache : false,
					url : "select_add_customer.jsp",
					dataType : "json",
					data : {
					count:count,
					name : $('#name').val(),
					address:$('#address').val(),
					area_id:$('#area_id').val(),
					type:$('#type').val(),
					phone:$('#phone').val(),
					business:$('#business').val(),
					creat_time:$('#creat_time').val(),
					origin:$('#origin').val(),

					l_name:$('#l_name').val(),
					l_gender:$('[name=l_gender]').val(),
					l_birthday:$('#l_birthday').val(),
					l_province_id:$('#l_province_id').val(),
					l_postion:$('#l_position').val(),
					l_email:$('#l_email').val(),
					l_phone:$('#l_phone').val(),
					l_hobby:$('#l_hobby').val(),
					l_qq:$('#l_qq').val()
					},
					success : function(data) {
						if (data.status == 1||data.status ==3) {
							window.location.reload();
						}
						if (data.status == 2) {
							alert("添加客户成功，添加联系人失败");
							window.location.reload();
						}
						if (data.status == 0) {
							alert("添加失败");
							window.location.reload();
						}
					}
				})
			})
	  })
  </script>
 </head>
 <body>
 <%
     int employeeId = ParamUtil.getInt(request,"id",0);
 %>
  <p class='title'>点击客户所在行即可选择该客户</p>
  <form>
  <table>
  <tr><td>客户名</td>
        <td>所属区域</td>
        <td>类型</td>
        <td>地址</td>
        <td>公司业务</td>
  </tr>
  <%
         List<Customer> cs = CustomerControl.getCustomersByEmployeeId(employeeId);
         for(Customer c : cs){
  
  %>
  <tr class="trs">
  <td class="td" style="display:none"><%=c.getId() %></td>
  <td class="td2"><%=c.getName() %></td>
  <td><%=SaleareaControl.getAreaName(c.getArea_id()) %></td>
  <td><%=c.getType() %></td>
  <td><%=c.getAddress() %></td>
   <td><%=c.getBusiness() %></td>
  </tr>
  <%} %>
  
  </table>
  </form>
		<p class='title'><input type="button" class='button' id="show" value="添加客户"></p>
		<div id="add_customer" >
                  <form name="form1" action="customer_add_do.jsp" method="post" >
         <table>
         <tr>
			<td>客户名称</td><td><input type="text" name="name" id="name" /></td>
			<td>客户地址</td><td><input type="text" name="address" id="address" /></td></tr><tr>
			<td>电话号码</td><td><input type="text" name="phone" id="phone" /></td>
			<td>所属区域</td><td><select name="area_id" id="area_id">
						<%
						Collection<Salearea> s = SaleareaControl.getAllSalearea();
					     Iterator<Salearea> its = s.iterator();
					     while(its.hasNext()){
					       Salearea salearea = its.next(); 
					    %>
					   <option value="<%=salearea.getId() %>"><%=salearea.getArea_name() %></option>
                      <%} %>
                      </select>
					</td></tr><tr>
				<td>客户类型</td><td><input type="radio" name="type" id="type" checked />一般<input type="radio" name="type" id="type" />重要</td>
				<td>客户来源</td><td><input type="text" name="origin" id="origin" /></td></tr><tr>
				<td>客户创建时间</td><td><input type="text" name="create_time" maxlength="20" id="creat_time"	readonly onClick="SelectDate(this,'yyyy-MM-dd')" /></td>
				<td>客户从事行业</td><td><input type="text" name="business" id="business" /></td>
			</tr>
		</table>
				<p class='title' ><input id="add_linkman" class='button' value='继续添加客户相关联系人'/></p>
				<div  id="show_add_linkman">
				<table>
				<tr>
				<td>联系人姓名</td><td><input type="text" value="" id="l_name"></td>
				<td>性别</td><td><input type="radio" name="l_gender" value="1" checked />
						男
						<input name="l_gender" type="radio" value="0" />
						女</td>
						</tr>
				<tr><td>生日</td><td><input type="text" name="l_birthday" id="l_birthday" maxlength="20" onClick="SelectDate(this,'yyyy-MM-dd')" /></td>
				<td>籍贯</td><td><select name="l_province_id" id="l_province_id">
							<%
								HashMap provinces = GetBaseParam.getAllProvinces();
								Iterator it1 = provinces.entrySet().iterator();
								while (it1.hasNext()) {
									Map.Entry entry = (Map.Entry) it1.next();
							%>
							<option value="<%=entry.getKey()%>"><%=entry.getValue()%></option>
							<%
								}
							%>
						</select></td>
						</tr>
					<tr><td>职位</td><td><input onclick="return false;" type="text" name="position" id="l_position"/></td>
					<td>邮件</td><td><input type="text" name="email" id="l_email" /></td></tr>
					<tr><td>联系号码</td><td><input type="text" name="phone" id="l_phone" /></td>
					<td>爱好</td><td><input type="text" name="hobby" id="l_hobby"/></td>
					</tr>
					<tr>
					<td>qq号</td><td ><input type="text" name="qq" id="l_qq"/></td>
					<td colspan='2'>&nbsp;</td>
					</tr>
					</table>
				</div>
<p class='title'><input name="Submit35" type="button" class='button' id ="submit_btn" value="确定" />&nbsp;&nbsp;&nbsp;&nbsp;
                       <input name="Submit333" type="button" class='button'  id="cancel" value="取消" />
                     </p>
                    </form>
</div>
  
</html>